package com.zeroxml.cms.service.impl;

import com.wyvoid.core.persistent.hibernate.HibernatePage;
import com.zeroxml.cms.bo.Article;
import com.zeroxml.cms.bo.Comment;
import com.zeroxml.cms.bo.User;
import com.zeroxml.cms.dao.IArticleDAO;
import com.zeroxml.cms.dao.ICommentDAO;
import com.zeroxml.cms.dao.IUserDAO;
import com.zeroxml.cms.exception.ArticleNotExistException;
import com.zeroxml.cms.service.ICommentService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * User: cjp
 * Date: 2007-9-20
 * Time: 9:15:54
 */
public class CommentService implements ICommentService {
    private IUserDAO userDAO;
    private IArticleDAO articleDAO;
    private ICommentDAO commentDAO;

    public void setUserDAO(IUserDAO userDAO) {
        this.userDAO = userDAO;
    }

    public void setArticleDAO(IArticleDAO articleDAO) {
        this.articleDAO = articleDAO;
    }

    public void setCommentDAO(ICommentDAO commentDAO) {
        this.commentDAO = commentDAO;
    }

    public HibernatePage<Comment> getComments(long articleId, int curPage, int pageSize) {
        return commentDAO.getComments(articleId, curPage, pageSize);
    }

    public List<Comment> getLatestComments(int size) {
        return commentDAO.getLatestComments(size);
    }

    @Transactional
    public void doComment(Comment comment) {
        commentDAO.create(comment);
    }
}
